package com.rul.mars.order.controller;

import com.rul.mars.mbg.domain.LeaseDetail;
import com.rul.mars.mbg.domain.LeaseParam;
import com.rul.mars.order.service.LeaseService;
import com.rul.mars.common.api.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 租赁服务接口
 *
 * @author RuL
 */
@RestController
@RequestMapping("/basic/lease")
public class LeaseController {

    @Autowired
    private LeaseService leaseService;

    /**
     * 查询租赁详情
     *
     * @param id 租赁ID
     * @return 租赁详情
     */
    @ApiOperation("查询租赁详情")
    @GetMapping("/detail/{id}")
    public CommonResult<LeaseDetail> detail(@PathVariable(value = "id") Long id) {
        LeaseDetail detail = leaseService.detail(id);
        return CommonResult.success(detail);
    }


    /**
     * 生成租赁单
     *
     * @param leaseParam 租赁参数
     * @return 租赁单生成结果
     */
    @ApiOperation("生成租赁单")
    @PostMapping("/generate")
    public CommonResult<LeaseDetail> generateLease(@RequestBody LeaseParam leaseParam) {
        LeaseDetail leaseDetail = leaseService.generateLease(leaseParam);
        return CommonResult.success(leaseDetail);
    }


    /**
     * 用户取消租赁
     *
     * @param id 租赁ID
     * @return 操作结果
     */
    @ApiOperation("用户取消租赁")
    @GetMapping("/cancel")
    public CommonResult cancelLease(@RequestParam(value = "id") Long id) {
        boolean success = leaseService.cancelLease(id);
        if (success) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    /**
     * 用户删除租赁信息
     *
     * @param id 租赁ID
     * @return 操作结果
     */
    @ApiOperation("用户删除租赁信息")
    @GetMapping("/delete")
    public CommonResult deleteLease(@RequestParam(value = "id") Long id) {
        boolean success = leaseService.deleteLease(id);
        if (success) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


    /**
     * 用户确认收货
     *
     * @param id 租赁ID
     * @return 操作结果
     */
    @ApiOperation("用户确认收货")
    @GetMapping("/confirmReceive")
    public CommonResult confirmReceive(@RequestParam(value = "id") Long id) {
        boolean success = leaseService.confirmReceive(id);
        if (success) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


}
